/*
 * @Descripttion:
 * @version: 1.0.0
 * @Author: Shentong
 * @Date: 2021-04-21 16:47:28
 * @LastEditors: shentong
 * @LastEditTime: 2022-02-24 20:47:33
 */
import request, { TaroHTTPConfig } from './request'

interface Response<T> {
    status: string;
    code: number | string;
    payload: T;
    errors: string;
    data?: T;
}

let serverUrl: string = ''

if (process.env.TARO_ENV === 'weapp') {
  switch (process.env.NODE_ENV) {
    case 'development':
      serverUrl = "https://c.jlshuangcheng.com";
      break;
    case 'test':
      serverUrl = "https://c.jlshuangcheng.com";
      break
    case "production":
      serverUrl = "https://c.jlshuangcheng.com";
      break;
    default:
      serverUrl = "https://c.jlshuangcheng.com";
      break;
  }
}

export const server = {
  POST: function<T, K>(url: string, data?: T, config?: TaroHTTPConfig) {
    return request<Response<K>>(serverUrl + url, 'POST', data, config)
  },
  GET: function<T, K>(url: string, data?: T, config?: TaroHTTPConfig) {
    return request<Response<K>>(serverUrl + url, 'GET', data, config)
  },
  AIAPPPOST: function<T, K>(url: string, data?: T, config?: TaroHTTPConfig) {
    return request<Response<K>>(serverUrl + url, 'POST', data, config)
  },
  AIAPPGET: function<T, K>(url: string, data?: T, config?: TaroHTTPConfig) {
    return request<Response<K>>(serverUrl + url, 'GET', data, config)
  }
}
